package leetcode.D100.T6;

/**
 * @File Info: leetcode -- <Solution>
 * @Author: DYZ
 * @Create: 2021-08-08 14:59:19 星期日
 */

public class Solution {
    public String convert(String s, int numRows) {
        if(numRows == 1) {
            return s;
        }
        StringBuilder[] sbs = new StringBuilder[numRows];
        for(int i=0; i<sbs.length; ++i) {
            sbs[i] = new StringBuilder();
        }
        int curRow = 0, direct = 1;
        for(int i=0; i<s.length(); ++i) {
            sbs[curRow].append(s.charAt(i));
            if(curRow == numRows-1) {
                direct = -1;
            } else if(curRow == 0) {
                direct = 1;
            }
            curRow = curRow + direct;
        }
        StringBuilder result = new StringBuilder();
        for(int i=0; i<numRows; ++i) {
            result.append(sbs[i].toString());
        }
        return result.toString();
    }
}
